package consulTest.Entity.Response;


import lombok.Data;

@Data
public class Response<T> {
    private boolean success;
    private String  errorCode;
    private String  errorMessage;
    private T       data;

    public static <T> Response<T> success() {
        Response<T> response = new Response<>();
        response.setSuccess(true);
        response.setErrorCode("0000");
        return response;
    }

    public static <T> Response<T> success(T t) {
        Response<T> response = new Response<>();
        response.setSuccess(true);
        response.setErrorCode("0000");
        response.setData(t);
        return response;
    }

    public static <T> Response<T> fail(String errorMsg) {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setErrorCode("99999999");
        response.setErrorMessage(errorMsg);
        return response;
    }

    public static <T> Response<T> loseConnection() {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setErrorCode("401");
        response.setErrorMessage("请重新登录");
        return response;
    }

    public static <T> Response<T> withoutAuthority() {
        Response<T> response = new Response<>();
        response.setSuccess(false);
        response.setErrorCode("403");
        response.setErrorMessage("无操作权限");
        return response;
    }

    public Response() {
    }
}